package org.lee.hello.prop;

import net.bytebuddy.ByteBuddy;
import net.bytebuddy.implementation.FixedValue;

import static net.bytebuddy.matcher.ElementMatchers.*;

/**
 * @author jackielee
 * @version 1.0
 * @description Foo
 * @date 2021/7/28
 **/
public class PropertyDemo {
    public static void main(String[] args) throws InstantiationException, IllegalAccessException {
        Foo dynamicFoo = new ByteBuddy()
                .subclass(Foo.class)
                .method(isDeclaredBy(Foo.class)).intercept(FixedValue.value("One"))
                .method(named("foo")).intercept(FixedValue.value("Two"))
                .method(named("foo").and(takesArguments(1))).intercept(FixedValue.value("Three"))
                .make()
                .load(PropertyDemo.class.getClassLoader())
                .getLoaded()
                .newInstance();
        System.out.println(dynamicFoo.bar());
        System.out.println(dynamicFoo.foo());
        System.out.println(dynamicFoo.foo(1));

    }
}

